package com.eorchis.module.util;  
  
import java.beans.PropertyDescriptor;  
import java.lang.reflect.Method;  
import java.lang.reflect.Modifier;  
import java.util.Arrays;  
import java.util.List;  
  
import org.springframework.beans.BeansException;  
import org.springframework.beans.FatalBeanException;  
  
public class BeanUtils extends org.springframework.beans.BeanUtils {  
  
  public static void copyProperties(Object source, Object target,String[] ignoreProperties) throws BeansException {  
    Class<?> actualEditable = target.getClass();  
    PropertyDescriptor[] targetPds = getPropertyDescriptors(actualEditable);  
    List<String> ignoreList = (ignoreProperties != null) ? Arrays.asList(ignoreProperties) : null;  
      
    for (PropertyDescriptor targetPd : targetPds) {  
      if (targetPd.getWriteMethod() != null&&  
              (ignoreProperties == null || (!ignoreList.contains(targetPd.getName())))) {  
        PropertyDescriptor sourcePd = getPropertyDescriptor(source.getClass(), targetPd.getName());  
        if (sourcePd != null && sourcePd.getReadMethod() != null) {  
          try {  
            Method readMethod = sourcePd.getReadMethod();  
            if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {  
              readMethod.setAccessible(true);  
            }  
            Object value = readMethod.invoke(source);  
            // 这里判断以下value是否为空 当然这里也能进行一些特殊要求的处理 例如绑定时格式转换等等  
            if (value != null) {  
              Method writeMethod = targetPd.getWriteMethod();  
              if (!Modifier.isPublic(writeMethod.getDeclaringClass().getModifiers())) {  
                writeMethod.setAccessible(true);  
              }  
              writeMethod.invoke(target, value);  
            }  
          } catch (Throwable ex) {  
            throw new FatalBeanException("Could not copy properties from source to target", ex);  
          }  
        }  
      }  
    }  
  }  
}  